import request from '@/utils/request'

// 查询广电用户列表
export function listGuangDianUser(query) {
  return request({
    url: '/system/guangdian/list',
    method: 'post',
    data: query
  })
}

// 查询广电用户详细
export function getGuangDianUser(id) {
  return request({
    url: '/system/guangdian/' + id,
    method: 'get'
  })
}

// 新增广电用户
export function addGuangDianUser(data) {
  return request({
    url: '/system/guangdian/add',
    method: 'post',
    data: data
  })
}

// 修改广电用户
export function updateGuangDianUser(data) {
  return request({
    url: '/system/guangdian/edit',
    method: 'post',
    data: data
  })
}

// 导入CSV数据
export function importGuangDianUserFromCsv(filePath, limit = 0) {
  return request({
    url: '/system/guangdian/importCsv',
    method: 'post',
    params: {
      filePath: filePath,
      limit: limit
    }
  })
}

/**
 * 获取仪表盘数据
 */
export function getDashboardData() {
  return request({
    url: '/system/guangDian/dashboardData',
    method: 'get'
  });
}

/**
 * 获取最近的用户数据
 * @param {number} limit - 返回记录数量
 */
export function getRecentUsers(limit) {
  return request({
    url: '/system/guangDian/recentUsers',
    method: 'get',
    params: { limit: limit || 10 }
  });
}

// 删除广电用户
export function delGuangDianUser(id) {
  return request({
    url: '/system/guangdian/remove',
    method: 'post',
    data: id
  })
}

// 导出广电用户
export function exportGuangDianUser(query) {
  return request({
    url: '/system/guangdian/export',
    method: 'post',
    data: query
  })
}

// 统计标签用户数量
export function countUserByTag(tagField, tagValue) {
  return request({
    url: '/system/guangdian/countByTag',
    method: 'post',
    data: { tagField, tagValue }
  })
}